![]() |
Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.3.23
|
Leadtools.Pdf Assembly > Leadtools.Pdf Namespace > PDFFile Class > MergeWith Method : MergeWith(String[],String) Method |
public void MergeWith( string[] sourceFileNames, string destinationFileName )
'Declaration
Public Overloads Sub MergeWith( _ ByVal sourceFileNames() As String, _ ByVal destinationFileName As String _ )
'Usage
Dim instance As PDFFile Dim sourceFileNames() As String Dim destinationFileName As String instance.MergeWith(sourceFileNames, destinationFileName)
public: void MergeWith( array<String^>^ sourceFileNames, String^ destinationFileName )
This method will merge two or more existing PDF files to form a new file containing all the pages from the pre-existing PDF files. The new file will be constructed as follows:
The pages of the PDF file associated with this PDFFile object will be first
The pages of the first file in the sourceFileNames list will be appended next
The pages of the second file in the sourceFileNames list will be appended next
And so on for each item in sourceFileNames.
All the PDF files must pre-exist on disk and must be valid. The sourceFileNames parameter must not contain any null items.
To use this method, associate this PDFFile object with a valid PDF file and optional password. You can achieve this by either using the PDFFile(string fileName) or PDFFile(string fileName, string password) constructors or set the filename and optional password directly into the FileName and Password properties. You do not need to call Load before using this method.
This method will use the following properties of this PDFFile object:
DocumentProperties. If the value of this property is null, then default properties will be used
SecurityOptions. If the value of this property is not null, then the destination file will be encrypted using the properties of this property. If the value of this property is null, the result file will not be encrypted
CompatibilityLevel. The version of the generated PDF file
If one or more of the files to merge with are encrypted with a password, then use the MergeWith(PDFFile[] sourceFiles, string destinationFileName) version of this method that allow you to pass a list of PDFFile objects instead of just the filenames, and thus, associated each input item with an optional password.
This example will merge a group of PDF files to generate a single document that contain all the pages.
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Pdf Imports Leadtools.WinForms Imports Leadtools.Svg Imports Leadtools.ImageProcessing <TestMethod> _ Public Sub PDFFileMergeWithExample() Dim sourceFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "File1.pdf") Dim sourceFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "File2.pdf") Dim sourceFileName3 As String = Path.Combine(LEAD_VARS.ImagesDir, "File3.pdf") Dim destinationFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Merged.pdf") ' Merge 1 with (2, 3) and form destination Dim pdfFile As PDFFile = New PDFFile(sourceFileName1) pdfFile.MergeWith(New String() {sourceFileName2, sourceFileName2}, destinationFileName) End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
using Leadtools; using Leadtools.Codecs; using Leadtools.Controls; using Leadtools.Drawing; using Leadtools.ImageProcessing; using Leadtools.Pdf; using Leadtools.Svg; using Leadtools.WinForms; [TestMethod] public void PDFFileMergeWithExample() { string sourceFileName1 = Path.Combine(LEAD_VARS.ImagesDir, @"File1.pdf"); string sourceFileName2 = Path.Combine(LEAD_VARS.ImagesDir, @"File2.pdf"); string sourceFileName3 = Path.Combine(LEAD_VARS.ImagesDir, @"File3.pdf"); string destinationFileName = Path.Combine(LEAD_VARS.ImagesDir, @"Merged.pdf"); // Merge 1 with (2, 3) and form destination PDFFile pdfFile = new PDFFile(sourceFileName1); pdfFile.MergeWith(new string[] { sourceFileName2, sourceFileName2 }, destinationFileName); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }